package com.ejlchina.tool.base

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.ViewGroup.LayoutParams
import androidx.fragment.app.DialogFragment
import com.ejlchina.tool.util.getScreenWidthHeight


open class BaseDialogFragment: DialogFragment() {

    override fun onStart() {
        super.onStart()
        resizeDialogFragment()
    }

    protected open fun resizeDialogFragment() {
        val dialog = dialog
        if (null != dialog) {
            val window = dialog.window!!
            window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            window.decorView.background = ColorDrawable(Color.TRANSPARENT)
            val lp = getDialog()!!.window!!.attributes
            lp.width = 5 * requireActivity().getScreenWidthHeight().first / 6
            window.setLayout(lp.width, LayoutParams.WRAP_CONTENT)
        }
    }
}